package com.topscore.uke.ui.fragments;


import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.topscore.uke.R;
import com.topscore.uke.ui.BaseSupportFragment;
import com.topscore.uke.utils.DisplayImageOptionsManager;

import java.util.ArrayList;
import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * A simple {@link Fragment} subclass.
 */
public class ArrangeFragment extends BaseSupportFragment {

    @Bind(R.id.recycler_view)
    RecyclerView recyclerView;
    private View rootView;

    private BaseQuickAdapter<String, BaseViewHolder> mRecyclerAdapter = new BaseQuickAdapter<String, BaseViewHolder>(R.layout.product_detail_image_item, new ArrayList<>()) {
        @Override
        protected void convert(BaseViewHolder holder, String item) {
            ImageView imageView = holder.getView(R.id.image_iv);
            ImageLoader.getInstance().displayImage(item, imageView, DisplayImageOptionsManager.getInstance().getDefaultOptions());
        }
    };

    public ArrangeFragment() {
        // Required empty public constructor
    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        rootView = inflater.inflate(R.layout.fragment_arrange, container, false);
        ButterKnife.bind(this, rootView);
        initViews();
        return rootView;
    }

    private void initViews() {
        recyclerView.setLayoutManager(new LinearLayoutManager(getActivity(), LinearLayoutManager.VERTICAL, false));

        recyclerView.setAdapter(mRecyclerAdapter);
    }

    public void setUpImageData(List<String> imagePaths) {
        mRecyclerAdapter.setNewData(imagePaths);
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        ButterKnife.unbind(this);
    }
}
